<?php
/**
 * Introduction: 短信发送接口类
 * @author: 杨陈鹏
 * @date: 2016/4/6 19:58
 * @email: yangchenpeng@cdlinglu.com
 */
namespace WeChat\Controller\Sms;


use Think\Controller;

class MobileController extends Controller
{

    /**
     * Introduction: 获取验证码
     * @author: 杨陈鹏
     * @date: 2016/4/1 08:42
     * @email: yangchenpeng@cdlinglu.com
     */
    public function code()
    {

        //用户逻辑
        //$logic = D('Common/Member', 'Logic');

        //获取短信类
        $sms = new \Think\SMS\Mobile();

        //生成验证码
        $code = random(4);

        $mobile = I('param.mobile');

        if (!preg_match("/^1[3|4|5|6|7|8]\d{9}$/", $mobile))
            outPut(['code' => 100, 'msg' => '手机号码格式错误!']);

        //$result = $logic::checkMobile($mobile);

        //if ($result['code'] == 300)
        //    outPut($result);

        //储存验证码
        session('mobile_code_' . $mobile, $code);

        $result = $sms->send($mobile, '您的验证码为: '.$code);

        outPut($result);

    }
    /**
     * Introduction: 注册是获取手机验证码
     * @author: 杨陈鹏
     * @date: 2016/4/1 08:42
     * @email: yangchenpeng@cdlinglu.com
     */
    public function getRegMobileCode()
    {

        //用户逻辑
        $logic = D('Common/Member', 'Logic');

        //获取短信类
        $sms = new \Think\SMS\Mobile();

        //生成验证码
        $code = random(4);

        $mobile = I('param.mobile');

        if (!preg_match("/^1[3|4|5|6|7|8]\d{9}$/", $mobile))
            outPut(['code' => 100, 'msg' => '手机号码格式错误!']);

        $result = $logic::checkMobile($mobile);

        if ($result['code'] == 300)
            outPut($result);

        //储存验证码
        session('mobile_code_' . $mobile,$code);

        $result = $sms->send($mobile,  '您的验证码为: '.$code);

        outPut($result);

    }

}